package com.example.day11;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

public class Myadapter extends BaseAdapter {
    ArrayList<String> arrayList;
    Context context;
    public Myadapter(Context context, ArrayList<String> arrayList){
        this.arrayList = arrayList;
        this.context=context;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder viewHolder;
        if(convertView==null){
            convertView=View.inflate(context,R.layout.layout,null);
            viewHolder=new viewHolder();
            viewHolder.imageView=convertView.findViewById(R.id.image1);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(viewHolder)convertView.getTag();
        }
        Glide.with(context).load(arrayList.get(position)).into(viewHolder.imageView);
        return convertView;
    }
    public class viewHolder{
        ImageView imageView;
    }
}
